package com.clqteam.controller;


import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.clqteam.model.Employee;

/**
 * 
 * @author CLQ
 *
 */

import com.clqteam.service.DeletEmployeeService;
import com.clqteam.service.EmployeeLoginService;
import com.clqteam.serviceimpl.DeletEmployeeServiceImpl;
import com.clqteam.serviceimpl.EmployeeLoginServiceImpl;
public class DeletEmployeeController extends HttpServlet{
	  DeletEmployeeService deService=new DeletEmployeeServiceImpl();
	  EmployeeLoginService emService=new EmployeeLoginServiceImpl();
   @Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	doPost(req, resp);
}
   
   @Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf8");
		resp.setCharacterEncoding("utf8");
		String[] e=req.getParameterValues("eid2");
	    for (String eid : e) {
	    	int eId=Integer.parseInt(eid);
	    	boolean bo=deService.deletEmployeeImpl(eId);
			PrintWriter out=resp.getWriter();
			  if(bo){
				  HttpSession session=req.getSession();
				  Employee emp=(Employee)session.getAttribute("employee");
				  SimpleDateFormat sd=new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
				  Date date=new Date();
				  String time=sd.format(date);
				  String info="删除员工";
				  emService.insertLoginTime(time, info, emp.geteId(),emp.geteName());
				  
				  out.write("1");
			  }else{
				  out.write("0");
			  }
			  out.flush();
			  out.close();
		}
		
	}
	
	
}
